<template>
  <div>
    <el-dialog title="选择职位" :visible.sync="jobSelectionBoolean" width="40%" custom-class="dialogClass"
      :before-close="handleClose">
      <span></span>
      <div class="companyTag">
        <el-table :data="tableData" v-loading="pictLoading" ref="multipleTable" style="width: 100%"
          @selection-change="handleSelectionChange" height="470">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column prop="name" label="职位名称" align="center">
          </el-table-column>
          <el-table-column prop="workAreaText" label="招聘地区" align="center" width="100">
          </el-table-column>
          <el-table-column prop="createTime" label="发布时间" align="center">
          </el-table-column>
          <el-table-column prop="refreshTime" label="刷新时间" align="center">
          </el-table-column>
          <el-table-column prop="expireTime" label="到期时间" align="center">
          </el-table-column>
        </el-table>
      </div>
      <hr>
      <div class="tag-group">
        <span class="tag-group__title"></span>
        <div class="pagination">
          <el-pagination background layout="prev, pager, next" @current-change="currentChange" :total="total">
          </el-pagination>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="center">取 消</el-button> -->
        <el-button type="primary" @click="confirm">添加职位</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<style scoped>
.companyTag {
    margin-top: 10px;
    display: flex;
    /* justify-content: space-between; */
    flex-wrap: wrap;
    flex-direction: row;
    max-height: 450px;
}
.companyTag .tag {
    height: 23px;
    display: inline-block;
    padding: 3px 20px;
    margin: 8px 6px;
    border: 1px solid rgba(232, 232, 232, 1);
    border-radius: 4px;
    font-size: 12px;
    font-family: PingFang SC;
    font-weight: 400;
    text-align: center;
    line-height: 23px;
    cursor: pointer;
    color: rgba(85, 85, 85, 1);
}
.companyTag /deep/ .el-table th > .cell {
    padding-left: 14px;
}
.selectTagClass {
    border: 1px solid rgba(24, 147, 252, 1) !important;
    position: relative;
}
.selectTagClass span img {
    width: 10px;
    height: 10px;
    position: absolute;
    right: 0;
    bottom: 0;
}
hr {
    margin: 23px 0;
    background: #e8e8e8;
}

.tag-group {
    display: flex;
}
.tag-group__title {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 20px;
    color: rgba(34, 34, 34, 1);
}

.elTag {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    width: 75%;
}
.elTag /deep/ .el-tag--plain {
    margin: 0px 10px 16px;
    padding: 0 5px;
    font-size: 12px;
    text-align: center;
    font-family: PingFang SC;
    font-weight: 400;
    /* padding: 2px 0; */
    color: rgba(24, 147, 252, 1);
}

.dialog-footer button {
    width: 120px;
    height: 34px;
    color: rgba(255, 255, 255, 1);
    background: #0093ff;
}
/* 自定义 */
.custom .esitTag {
    display: flex;
    align-items: center;
    color: #0093ff;
}
.custom .esitTag img {
    margin: 0 5px;
}
.pagination {
    margin: 0 auto;
}
</style>
<style>
.dialogClass .el-dialog__header {
    border-bottom: 1px solid rgba(0, 147, 255, 1);
}
.dialogClass .el-dialog__headerbtn .el-dialog__close {
    color: rgba(0, 147, 255, 1);
}
.dialogClass .el-dialog__title {
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 600;
    line-height: 16px;
    color: rgba(34, 34, 34, 1);
}
.dialogClass .el-dialog__body {
    padding: 10px 30px;
}
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
    background-color: #fff;
}
::-webkit-scrollbar-thumb {
    /* // border-radius:5px; */
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    background-color: rgba(0, 0, 0, 0.1);
}
</style>

<script>
import { getPageLists, getfindById } from '../../../../api/jobfair';
export default {
  name: 'setCompanyLabel',
  props: {
    jobSelectionBoolean: {
      type: Boolean,
      default: false
    },
    companyId: {
      type: String | Number,
      default: ''
    },
    domains: {
      type: Array,
      default: []
    }
  },
  data () {
    return {
      //   弹框默认隐藏
      // jobSelectionBoolean: false,
      // 表格数据
      tableData: [],
      // 父页面过来的数据
      jobList: [],
      // 公司ID
      company: '',
      total: 1, // 总条数
      allureArr: [],
      queryObj: {
        page: 1,
        size: 10,
        condition: [
          { column: 'status', type: "eq", value: 1 },
          { "column": "include", "type": "", "value": "D" }
        ],
        sort: 'asc'
      },
      // 选择的数据
      handleSelection: [],
      pictLoading: false
    }
  },
  watch: {
    companyId: {
      handler (newVal, oldVal) {
        this.company = newVal
      },
      immediate: true
    },
    domains: {
      handler (newVal, oldVal) {
        this.jobList = newVal
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    handleClose (done) {
      this.$emit('close', false)
    },
    confirm () {
      this.$emit('close', false)
      this.$emit('handleSelection', this.handleSelection)
    },
    //   分页
    currentChange (val) {
      console.log(val)
      this.queryObj.page = val
      this.getPage()
    },
    handleSelectionChange (val) {
      // this.$emit('handleSelection', val)
      this.handleSelection = val
    },
    getPage () {
      let that = this
      that.pictLoading = true
      console.log(that.queryObj.condition, 'that.queryObj.condition')
      let forFata = new FormData()
      forFata.append('condition', JSON.stringify(that.queryObj.condition))
      forFata.append('size', 10)
      forFata.append('page', that.queryObj.page)
      getPageLists(forFata).then((data) => {
        if (data.success) {
          that.pictLoading = false
          // that.$nextTick(() => {
          let datas = data.data.records
          that.tableData = datas
          that.total = data.data.total
          that.getfindById()
          console.log(data.data.records, '成功')
        } else {
          that.pictLoading = false
        }
      }).catch(() => {
        that.pictLoading = false
      })
    },
    // 请求修改的数据
    getfindById () {
      let that = this
      // if (that.$refs.multipleTable) {
      //   getfindById(that.$route.query.id).then((res) => {
      //     if (res.success) {
      // let datats = this.jobList
      // let allureArr = []
      if (that.jobList.length > 0) {
        that.tableData.map((item) => {
          that.$nextTick(() => {
            that.jobList.map((v) => {
              console.log(item.id == v.id)
              if (item.id == v.id) {
                that.$refs.multipleTable.toggleRowSelection(item, true);
              }
            })
          })
        })
        console.log(that.jobList, 'that.jobList')
      }
      //     } else {
      //       this.$message.error(res.msg)
      //     }
      //   })
      // }
    }
  },
  mounted () {
    this.getPage()
  }
};
</script>